package com.ruoyi.web.meetingUtil;

import com.ruoyi.meeting.domain.TmdMeetingApplication;
import com.ruoyi.meeting.domain.TmdMeetingManager;
import com.ruoyi.meeting.service.ITmdMeetingApplicationService;
import com.ruoyi.meeting.service.ITmdMeetingManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 功能:
 * 作者:胡丁一
 * 日期:2024/5/5 17:13
 */
@Component("conferenceTask")
public class AutoTask {

   @Autowired
   private ITmdMeetingApplicationService tmdMeetingApplicationService;

   @Autowired
   private ITmdMeetingManagerService tmdMeetingManagerService;

   public void getConferenceList() {
      List<TmdMeetingApplication> tmdMeetingApplications = tmdMeetingApplicationService.selectTmdMeetingApplicationList(new TmdMeetingApplication());
      for (TmdMeetingApplication eve : tmdMeetingApplications) {
         Date meetBeginTime = eve.getStartTime();
         Date meetEndTime = eve.getEndTime();
         // 获取当前会议使用的会议室
         Long roomId = eve.getAddressId();
         TmdMeetingManager tmdMeetingManager = tmdMeetingManagerService.selectTmdMeetingManagerById(roomId);
         // 获取当前系统时间
         Date nowDateTime = new Date();
         //比当前时间后，比结束时间早：进行中
         if (nowDateTime.after(meetBeginTime) && nowDateTime.before(meetEndTime)) {
            if (eve.getStatus() != 1) {
               // 设置会议状态
               eve.setStatus(1L);
               // 设置会议室状态
               tmdMeetingManager.setStatus(1L);
               //执行更新语句
               tmdMeetingApplicationService.updateTmdMeetingApplication(eve);
               tmdMeetingManagerService.updateTmdMeetingManager(tmdMeetingManager);
            }
            //结束时间比现在前边
         } else if (nowDateTime.after(meetEndTime)) {
            if (eve.getStatus() != 2) {
               // 设置会议状态
               eve.setStatus(2L);
               // 设置会议室状态
               tmdMeetingManager.setStatus(0L);
               //执行更新语句
               tmdMeetingApplicationService.updateTmdMeetingApplication(eve);
               tmdMeetingManagerService.updateTmdMeetingManager(tmdMeetingManager);
            }
         }
      }
   }
}